home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / irit / dosintr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  3.1 KB  |  111 lines

  1. /******************************************************************************
  2. *   "Irit" - the 3d (not only polygonal) solid modeller.              *
  3. *                                          *
  4. * Written by:  Gershon Elber                 Ver 0.2, Mar. 1990   *
  5. *******************************************************************************
  6. * Procedures to handle the dos interface - print/change the current dir. etc. *
  7. ******************************************************************************/
  8.  
  9. #include <sys/types.h>
  10. #ifdef DJGCC
  11. #include <dir.h>
  12. #endif /* DJGCC */
  13. #ifdef __WINNT__
  14. #include <direct.h>
  15. #endif /* __WINNT__ */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20. #include <errno.h>
  21. #include "program.h"
  22. #include "dosintr.h"
  23. #include "ctrl-brk.h"
  24. #include "windows.h"
  25.   
  26. #ifdef AMIGA
  27. #undef DOUBLE
  28. #ifdef __SASC
  29. #include <proto/dos.h>
  30. #endif /* __SASC */
  31. #ifdef __GNUC__
  32. #include <dos/dos.h>
  33. #include <inline/dos.h>
  34. #endif
  35. #endif /* AMIGA */
  36.  
  37. /*****************************************************************************
  38. *   Routine to change current directory                         *
  39. *****************************************************************************/
  40. void DosChangeDir(char *s)
  41. {
  42. #ifdef DJGCC
  43.     char cwd[LINE_LEN], *sptr;
  44.  
  45.     getcwd(cwd, LINE_LEN-1);               /* Save current position. */
  46.  
  47.     if (s[1] == ':')
  48.         sptr = &s[2];                /* Sptr points on the path only. */
  49.     else
  50.     sptr = s;
  51.  
  52.     if (strlen(sptr) != 0 && chdir(s))
  53.     WndwInputWindowPutStr("CHDIR: No Such Dir!");
  54.  
  55.     if (getcwd(s, LINE_LEN-1) == NULL) {      /* Test if directory is valid! */
  56.     WndwInputWindowPutStr("CHDIR: hardware (!?) error - ignored");
  57.     /* Restore old working directory: */
  58.     if (strlen(&cwd[2]) != 0)
  59.         chdir(cwd);                  /* If directory is not root... */
  60.     }
  61. #else
  62.     chdir(s);
  63. #endif /* DJGCC */
  64. }
  65.  
  66. /******************************************************************************
  67. * Procedure to return current time from last time, time was reset.          *
  68. * Time is reset if the given parameter is non zero. Time is returned in       *
  69. * seconds.                                      *
  70. ******************************************************************************/
  71. double DosGetTime(double ResetTime)
  72. {
  73.     return IritCPUTime(!APX_EQ(ResetTime, 0.0));
  74. }
  75.  
  76. /******************************************************************************
  77. * Procedure to execute a command.                          *
  78. ******************************************************************************/
  79. void DosSystem(char *Str)
  80. {
  81.     char Buffer[LINE_LEN_LONG];
  82. #   ifdef __UNIX__
  83.         int pid = getpid();
  84. #   else
  85.         int pid = (int) IritRandom(0.0, 10000.0);
  86. #   endif /* __UNIX__ */
  87.  
  88.     sprintf(Buffer, "%s > irit_tmp.%d", Str, pid);
  89. #ifdef AMIGA
  90.     if (SystemTagList(Buffer, NULL))
  91. #else
  92.     if (system(Buffer))
  93. #endif
  94.     WndwInputWindowPutStr("Undefined error in attempt to run command");
  95.     else {
  96.     FILE *f;
  97.  
  98.     sprintf(Buffer, "irit_tmp.%d", pid);
  99.     if ((f = fopen(Buffer, "r")) != NULL) {
  100.         while (fgets(Buffer, LINE_LEN_LONG - 1, f))
  101.         WndwInputWindowPutStr(Buffer);
  102.         fclose(f);
  103.  
  104.         sprintf(Buffer, "irit_tmp.%d", pid);
  105.         unlink(Buffer);
  106.     }
  107.     else
  108.         WndwInputWindowPutStr("Failed to read redirected output");
  109.     }
  110. }
  111.